<!--tvm票款差异协查-->
<template>
  <div class="JieZhangDanAndSCCengji el-card is-always-shadow el-card__body">
    <avue-crud
      ref="crud"
      :option="option"
      :table-loading="listLoading"
      :data="data"
      :page.sync="page"
      @search-change="handleFilter"
      @selection-change="selectionChange"
      @refresh-change="getList"
      @on-load="getList"
      :cell-class-name="addClass"
       >
      <template slot="menuRight">
        <el-button type="primary"  size="mini" @click="exportData">导出</el-button>
      </template>
      <template slot-scope="scope" slot="lineCodeSearch">
        <el-select v-model="searchForm.lineCode" placeholder="请选择" style="width: 150px" @change="changeLine" clearable filterable>
          <el-option
            v-for="(item,index) in lineCodes"
            :key="index"
            :label="item.name"
            :value="item.code">
          </el-option>
        </el-select>
      </template>
      <template slot-scope="scope" slot="stationCodeSearch">
        <el-select v-model="searchForm.stationCode" placeholder="请选择" style="width: 150px" clearable @change="changeStation" filterable>
          <el-option
            v-for="(item,index) in stationCodes"
            :key="index"
            :label="item.name"
            :value="item.code">
          </el-option>
        </el-select>
      </template>
      <template slot-scope="scope" slot="settleTimeSearch">
        <el-date-picker
          v-model="searchForm.settleTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="发生日期">
        </el-date-picker>
      </template>
      <template slot-scope="scope" slot="tvmOrderSearch">
        <el-select v-model="searchForm.tvmOrder" placeholder="请选择" style="width: 150px" filterable clearable>
          <el-option
            v-for="(item,index) in tvmCodes"
            :key="index"
            :label="item.tvmCode"
            :value="item.tvmCode">
          </el-option>
        </el-select>
      </template>
      <template slot="searchMenu" slot-scope="{row,size}">
        <el-button :size="size" @click="()=>{setSearchFiledsEmpty(row);setSearchFiledsEmpty(searchForm)}" icon="el-icon-delete">清空</el-button>
      </template>
      <template slot-scope="scope" slot="menu">
        <el-button type="text" size="small" plain @click.stop="previewEditor(scope.row,2)">预览</el-button>
<!--        <el-button type="text" v-if="!/\d+/g.test(scope.row.jdReplyReason)" size="small" plain @click.stop="previewEditor(scope.row,1)">回馈原因</el-button>-->
      </template>
    </avue-crud>
    <HuikuiInfo ref="HuikuiInfo" v-if="isShowDia"></HuikuiInfo>

    <el-dialog :visible="isShowDiaBatchFeedback" @close="isShowDiaBatchFeedback=false">
      <el-form>
        <el-form-item label="机电专业回馈差异原因：">
          <el-select v-model="batchParam.jdReplyReason" placeholder="请选择" style="width: 150px">
            <el-option
              v-for="(item,index) in getMappingStatusArray('JD_REPLY_REASON')"
              :key="index"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="机电专业详细描述：">
          <el-input type="textarea" v-model="batchParam.jdReplyDetail"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleSubmit" >确认</el-button>
          <el-button @click="isShowDiaBatchFeedback=false" >返回</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
</div>
</template>

<script>
    import {getForm, postForm} from '@/api/gen/gen'
    import moment from "moment";
    import HuikuiInfo from './FQXCJCY/HuikuiInfo';
    import {
      clearSelect, fenExYuangettoFixed,
      getgetStationCodes,
      getLineCodes, getMappingStatusArray, getSwPmTvmCodeList,getStationByCode,getLineAllAsyn,
      setSearchFiledsEmpty,
    } from "../../../../../../../api/subwayRat/commonCheck";

    import transitUtil from "../../../../../../../api/subwayRat/transitUtil";
    import {exportDataToExcel} from "../../../../../../../api/subwayRat/exportSelf";
    import {
      batchSwAuTvmCashboxAmountHierarchyDifference,
      FQXCJCY_option,
      getSwAuTvmCashboxAmountHierarchyDifferenceListOther, updateSwAuTvmCashboxAmountHierarchyDifference
    } from "../../../../../../../api/stationTiecketManager/shuJuXieChaGuanLi/TVM/XT/CJCY/FQXCJCY/FQXCJCY";

    export default {
      components:{
        HuikuiInfo,
        moment
      },
      data() {
            return {
              isShowDia:false,
              isShowDiaBatchFeedback:false,
              listLoading: true,
              lineCodes:[],
              stationCodes:[],
              tvmCodes:[],
              selectKeys:[], //存放对像
              selectKeyVals:[], //存放值
              data: [],
              batchParam:{},//批量参数
              searchForm:{
                lineCode:'',
                stationCode:'',
                tvmOrder:''
              },
              page: {
                total: 0, // 总页数
                currentPage: 1, // 当前页数
                pageSize: 20, // 每页显示多少条,
                isAsc: false// 是否倒序
              },
              option:{ },
            }
        },
        created() {
        this.getOption();
        },
        methods: {
          setSearchFiledsEmpty,
          getMappingStatusArray,
          handleSubmit(){
            let param={};
            param.ids=this.selectKeyVals.join(",");
            param.jdReplyReason=this.batchParam.jdReplyReason;
            param.jdReplyDetail=this.batchParam.jdReplyDetail;
            batchSwAuTvmCashboxAmountHierarchyDifference(param).then(res=>{
              if(res.data.code==0){
                this.$message.success("操作成功！");
                this.getList();
                this.isShowDiaBatchFeedback=false;
              }else{
                this.$message.error(res.data.msg);
              }
            })
          },
          openBatchHuiKui(){
            if(this.selectKeys.length<=0){
              this.$message.warning("请选择至少一条数据！");
              return;
            }
            for(let i=0;i<this.selectKeys.length;i++){
              if(/\d+/g.test(this.selectKeys[i].jdReplyReason)){
                this.$message.warning("请选择未回馈数据！");
                return;
              }
            }
            this.isShowDiaBatchFeedback=true;
          },
          cellStyle({row,column,rowIndex,columnIndex}){
              if(row.qingdian<0 && columnIndex==10 ){
                return {
                  color:'red'
                };
              }
          },
          addClass({row,column,rowIndex,columnIndex}){
            if(columnIndex==10){
              return 'qingdian';
            }
          },
          getList() {
            this.listLoading = true;
            Object.assign(this.searchForm,this.page);
            getSwAuTvmCashboxAmountHierarchyDifferenceListOther(this.searchForm).then((response)=>{
              // this.data = response.data.data;
              // this.listLoading = false;
              // this.page.total=response.data.total;
              this.data = response.data.data.list;
              this.listLoading = false;
              this.page.total=response.data.data.pageInfo.total;
            });
          },
          selectionChange(list){
            this.selectKeys=list;
            this.selectKeyVals=[];
            for(let i=0;i<list.length;i++){
              this.selectKeyVals.push(list[i].id);
            }
          },
          handleFilter(params, done) {
            Object.assign(this.searchForm,params);
            this.getList()
            done()
          },
          previewEditor(row,type){ //回馈预览
            this.isShowDia=true;
            this.$nextTick(()=>{
              this.$refs.HuikuiInfo.recallShow(row.id,row,type,row.replaceStatus,this);
            })
          },
          changeLine(v){ //改变线路时
            let p={};
            p.line_code=v;
            getStationByCode(p).then(res=>{
              this.stationCodes=res.data;
              this.searchForm.stationCode='';
              this.searchForm.tvmOrder='';
            })
          },
          changeStation(v){ //改变车站
            let param={};
            param.lineCode=this.searchForm.lineCode;
            param.stationCode=v;
            getSwPmTvmCodeList(param).then(r=>{
              this.tvmCodes=r.data;
            });
          },
          isassistInvestStatus(){ // 是否协查
            for(let i=0;i<this.selectKeys.length;i++){
              let row=this.selectKeys[i];
              if(row.assistStatus==3){
                return false
              }
            }
            return true;
          },
          async exportData(){ // 导出
            this.searchForm.pageNo=1;
            this.searchForm.pageSize=1000000000;
            if(this.selectKeys.length>0){
              let newData = JSON.parse(JSON.stringify(this.selectKeys));
              exportDataToExcel(newData,this.option.column,'分钱箱层级差异待协查');
            }else {
              let res=await getSwAuTvmCashboxAmountHierarchyDifferenceListOther(this.searchForm);
              let data = res.data.data;
              exportDataToExcel(data,this.option.column,'分钱箱层级差异待协查');
            }
          },
          getOption(){
            let th=this;
            this.option=FQXCJCY_option(true);
          },
          getLcOrScAmount(originType,needType,thisData){ //结账金额或者 sc
            if((originType+"")==(needType+"")){
              return thisData;
            }else{
              return 0;
            }
          },
          getChaYi(row,compareFirst,compareSec){ //结账金额 sc 差额
            let first=this.getLcOrScAmount(row.type,1,row[compareFirst]);//结账金额
            let sec=this.getLcOrScAmount(row.compareType,2,row[compareSec]); //sc
            return sec-first;
          },
          otherVueAction(){ //供其他Vue页面调用
            let th=this;
            transitUtil.$on('FQX_SC_call',(param)=>{
              console.log(param);
              getSwAuTvmCashboxAmountHierarchyDifferenceListOther({relationSourceboxId:param.id}).then((response)=>{
                th.data = response.data.data;
//                th.data[0].replaceStatus=1;//这里为什么要把替换状态换成1？？？
                th.previewEditor(th.data[0]);
              });
            })
            transitUtil.$on('FQX_SC_view',(param)=>{
              this.searchForm.relationSourceboxId = param.id;
              this.getList();
            });
          }
        },
      mounted() {
        getLineAllAsyn().then(res=>{ //获取线路
          this.lineCodes=res.data;
        });
        this.otherVueAction();
      }
    }
</script>
<style lang="scss">
</style>
